cmake_minimum_required( VERSION 2.8 )

#adapted from http://stackoverflow.com/questions/3065220/ctest-with-multiple-commands

macro( test_parser EXE_PATH DMI_FILE TEST_TYPE )
  set( parser_exe ${EXE_PATH}/dmisParser )
  set( lines_exe ${EXE_PATH}/removeLines )
  set( reformat_exe ${EXE_PATH}/reformatDmis )
  set( OK ../../parserTestFiles/okOut/OK.out )

  execute_process( COMMAND ${parser_exe} ${DMI_FILE} > junk1
                   RESULT_VARIABLE pars_result )
   if(pars_result)
       message(FATAL_ERROR "Error running ${parser_exe} on ${DMI_FILE}")
   else()
   execute_process( COMMAND ${lines_exe}
#     #compare input and output. they should match
#     execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files junk1 junk1.back
#                       RESULT_VARIABLE CMP_RESULT)
#     if(CMP_RESULT)
#         message(FATAL_ERROR "checkLevels - cycle test failed on ${DMI_FILE}")
#     else()
#       #delete temp files
#       execute_process( COMMAND ${CMAKE_COMMAND} -E remove junk1 junk1.back )
#     endif()
   endif()
endmacro()

test_parser( ${EXEC_PATH} ${DMI} ${TTYPE} )


function runOK
{
   echo $1
   ../../bin/dmisParser $1 > junk1
   ../../bin/removeLines $OK junk1 temp1
   if  [ "$?" -ne "0" ]; then
     echo "message test failed"
     return 1
   fi
   ../../bin/reformatDmis $1 > temp2
   diff temp1 temp2 > junk2
   if [ "$?" -ne "0" ]; then
     echo "cycle test failed"
     return 1
   fi
   return 0
}

function runOut
{
   echo $1
   ../../bin/dmisParser $1 > junk1
   ../../bin/removeLines $2 junk1 temp1
   if [ "$?" -ne "0" ]; then
     echo "message test failed"
     return 1
   fi
   return 0
}